home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / rlib.zip / RL_PICKF.PRG < prev    next >
Text File  |  1993-01-04  |  3KB  |  80 lines

  1. * Function: PICKFILE
  2. * Author..: Richard Low
  3. * Syntax..: PICKFILE( [filespec [,top, left, bottom [,colors [,expanded ]]]] )
  4. * Returns.: Filename picked from a boxed directory listing.
  5. *
  6.  
  7. FUNCTION PICKFILE
  8. PARAMETERS p_filespec, p_trow, p_tcol, p_brow, p_colors, p_expanded
  9. PRIVATE f_elements, f_bcol, f_pick, f_incolor
  10.  
  11. *-- if no filespec given or it is empty, default to all files
  12. p_filespec = IF( TYPE('p_filespec') = 'C',;
  13.              IF( EMPTY(p_filespec), '*.*', p_filespec ), '*.*' )
  14.  
  15. *-- default mode is wide display
  16. p_expanded = IF( TYPE('p_expanded') = 'L', p_expanded, .T. )
  17.  
  18. *-- if all three <top left bottom> cordinates are not numeric
  19. IF TYPE('p_trow') + TYPE('p_tcol') + TYPE('p_brow') != 'NNN'
  20.    *-- center the display in the middle of the screen
  21.    p_trow =  6
  22.    p_brow = 19
  23.    *-- width of display (including box) is 43 if expanded, 14 otherwise
  24.    p_tcol = (80 - IF(p_expanded,43,14)) / 2
  25. ELSE
  26.    *-- make sure top row is within screen limits
  27.    p_trow = IF( p_trow < 0 .OR. p_trow > 20, 6, p_trow )
  28.  
  29.    *-- make sure window will fit given top column, adjust left if needed
  30.    p_tcol = IF( p_tcol > IF(p_expanded,38,67), IF(p_expanded,38,67), p_tcol )
  31.  
  32.    *-- make sure bottom row is greater than top row
  33.    p_brow = IF( p_brow < p_trow+2 .OR. p_brow > 24, 20, p_brow )
  34. ENDIF
  35.  
  36. *-- if color not specified or is empty, use the current color
  37. p_colors = IF( TYPE('p_colors') = 'C',;
  38.            IF( EMPTY(p_colors), SETCOLOR(), p_colors ), SETCOLOR() )
  39.  
  40. *-- get the number of files matching <filespec>
  41. p_filespec = TRIM(p_filespec)
  42. f_elements = ADIR(p_filespec)
  43.  
  44. IF f_elements = 0
  45.    SAYINBOX( 'No files found matching ', p_filespec, 5 )
  46.    RETURN ''
  47. ENDIF
  48.  
  49. DECLARE dirlist[f_elements]                                      && set up array to hold list of filenames
  50. IF p_expanded
  51.    DECLARE size[f_elements], date[f_elements], time[f_elements]
  52.    ADIR( p_filespec, dirlist, size, date, time )                 && fill array with filenames
  53.    FOR x = 1 TO LEN(dirlist)                                     && if including extension
  54.       dirlist[x] = SUBSTR(dirlist[x] + SPACE(12),1,12) +;
  55.                    TRANSFORM(size[x],'  ##,###,###  ') +;
  56.                    DTOC(date[x]) + '  ' +;
  57.                    SUBSTR(time[x],1,5)                           && make all names 12 characters long
  58.    NEXT x                                                        && (pad with trailing spaces if needed)
  59. ELSE
  60.    ADIR( p_filespec, dirlist )                                   && fill array with filenames
  61.    FOR x = 1 TO LEN(dirlist)                                     && if including extension
  62.       dirlist[x] = SUBSTR(dirlist[x] + SPACE(12),1,12)
  63.    NEXT x                                                        && (pad with trailing spaces if needed)
  64. ENDIF
  65.  
  66. p_brow = IF( f_elements < (p_brow - p_trow), p_trow + f_elements + 1, p_brow )
  67. f_bcol = p_tcol + IF(p_expanded,41,12) + 1
  68.  
  69. f_window = SAVESCREEN( p_trow, p_tcol, p_brow, f_bcol )
  70.  
  71. f_incolor = SETCOLOR(p_colors)
  72. @ p_trow, p_tcol, p_brow, f_bcol BOX '╔═╗║╝═╚║'
  73.  
  74. f_pick = ACHOICE( p_trow+1, p_tcol+1, p_brow-1, f_bcol-1, dirlist )
  75.  
  76. RESTSCREEN( p_trow, p_tcol, p_brow, f_bcol, f_window )
  77. SETCOLOR(f_incolor)
  78.  
  79. RETURN IF( f_pick = 0, '', TRIM(SUBSTR(dirlist[f_pick],1,12)) )
  80.